﻿function Ctrl($scope, $http) { 
    $scope.password = { pattern: /^[a-zA-Z0-9_]*$/,check:function(){
        if ($scope.form.password.$valid)
            $scope.confirm.change();
    }};
    $scope.confirm = { change: function () {
        $scope.confirm.error = $scope.form.confirm.$valid && ($scope.password.value != $scope.confirm.value);
    }};
    $scope.verifyvalue = { pattern: /^[a-zA-Z0-9]{4,4}$/ };
    $scope.newverifycode = function () {
        $scope.verifycode = "/identity/verifycode?" + (new Date()).getTime().toString();
    };
    $scope.submit = function () {
        if (!$scope.form.$valid || $scope.confirm.error) {
            alert('信息填写不正确');
            return;
        }
        var param = { newpassword: $scope.password.value, verifyvalue: $scope.verifyvalue.value };
        $http({ method: 'POST', url: '/account/modifypassword'+location.search, data: param }).success(
		function (data, status) {
		    var result = angular.fromJson(data);
		    switch (result) {
		        case '0001': alert('验证码错误'); reset(); break;
		        case '0002': alert('无效安全身份'); reset(); break;
		        case '0003': alert('服务器繁忙，请稍候再试'); reset(); break;
		        default:
		            location.href = "/pwdBack05.html";
		    }
		}).error(function (data, status) {
		    alert('系统异常，请联系我们');
		});
    };
    $scope.lang = {
        password: { min: '密码长度为6-14个字符', max: '密码为超长，目前仅支持6-14位密码', pattern: '格式错误！！只能由数字,字母或下滑线构成', input: '密码长度为6-16个字符，由英文字母、数字构成' }
        , confirm: { error: '与输入密码不一致' }
        , verifyvalue: { pattern: '对不起，您输入的验证码错误', input: '请输入下面图标显示的数字或字母' }
    };
    function reset() {
        $scope.verifyvalue.value = "";
        $scope.newverifycode();
    }
    $scope.newverifycode();
}